package com.ruoyi.system.service.impl;

import com.ruoyi.system.mapper.ChartMapper;
import com.ruoyi.system.service.IChartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ChartServiceImpl implements IChartService {

    @Autowired
    private ChartMapper chartMapper;

    @Override
    public List<Map<String, Object>> getRepairCountByDate(String timeRange) {
        int days = convertTimeRangeToDays(timeRange);
        Map<String, Object> params = new HashMap<>();
        params.put("days", days);
        return chartMapper.selectRepairCountByDate(params);
    }

    @Override
    public List<Map<String, Object>> getOccupancyStatusCount() {
        return chartMapper.selectOccupancyStatusCount();
    }

    private int convertTimeRangeToDays(String timeRange) {
        switch (timeRange) {
            case "7d":
                return 7;
            case "30d":
                return 30;
            case "90d":
                return 90;
            default:
                return 7;
        }
    }
}